home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 11
/
FM Towns Free Software Collection 11.iso
/
t_os
/
tool
/
artemis1
/
usrlib
/
include
/
vector.h
< prev
Wrap
C/C++ Source or Header
|
1992-09-13
|
5KB
|
112 lines
/*
* Vector演算関数 ver 1.12
*
* math.h, math2.h を仮定する。
*/
/*
* 型宣言
*/
struct vect2i { int x ; int y }; /* 二次元整数vector */
struct vect3i { int x ; int y ; int z }; /* 三次元整数vector */
struct vect3p { int x; int y ; int z }; /* 三次元固定少数vector */
struct vect3f { float x ; float y ; float z }; /* 三次元浮動少数vector */
struct matrix3i { int xx ; int xy ; int xz ;
int yx ; int yy ; int yz ;
int zx ; int zy ; int zz ; }; /* 3×3整数行列 */
struct matrix3p { int xx ; int xy ; int xz ;
int yx ; int yy ; int yz ;
int zx ; int zy ; int zz ; }; /* 3×3固定少数行列 */
struct surfi {
struct vect3i norl; /* 法線 (NORmal Line) */
struct vect3i s0; /* 面上の一点 */
int c; /* 定数 */
};
struct surfp {
struct vect3p norl; /* 法線 (NORmal Line) */
struct vect3p s0; /* 面上の一点 */
int c; /* 固定少数の定数 */
};
/*
* 固定少数整数変換関数
*/
extern struct vect3i DeciToInt3V( struct vect3p p );
extern struct vect3p IntToDeci3V( struct vect3i p );
extern struct matrix3i DeciToInt3M( struct matrix3p A );
extern struct matrix3p IntToDeci3M( struct matrix3i A );
/*
* vector 演算関数
*/
#define MakeZero2i( p ) { (p).x=0; (p).y=0; }
#define MakeZero2p( p ) { (p).x=0; (p).y=0; }
extern struct vect2i scalar2i( int, struct vect2i ) ;
extern struct vect2i inscalar2i( int, struct vect2i );
extern struct vect2i scalar2p( int, struct vect2i );
extern struct vect2i add2i( struct vect2i, struct vect2i );
extern struct vect2i subtr2i( struct vect2i, struct vect2i );
extern struct vect2i rshift2i( struct vect2i, int );
extern struct vect2i lshift2i( struct vect2i, int );
#define iszero2( p ) ( (p).x==0 && (p).y==0 )
#define abs2i( p ) ( (int)sqrt( (p).x*(p).x + (p).y*(p).y ) )
#define innerpro2i( p, q ) ( (p).x*(q).x + (p).y*(q).y )
#define innerpro2p( p, q ) AdjMulDeci( (p).x*(q).x + (p).y*(q).y )
#define issame2v( p, q ) ( (p).x==(q).x && (p).y==(q).y )
#define MakeZero3i( p ) { (p).x=0; (p).y=0; (p).z=0; }
#define MakeZero3p( p ) { (p).x=0; (p).y=0; (p).z=0; }
extern struct vect3i scalar3i( int, struct vect3i );
extern struct vect3i scalar3p( int, struct vect3i );
extern struct vect3i inscalar3i( int, struct vect3i );
extern struct vect3i add3i( struct vect3i, struct vect3i );
extern struct vect3p add3p( struct vect3p x1, struct vect3p x2 );
extern struct vect3i subtr3i( struct vect3i, struct vect3i );
extern struct vect3p subtr3p( struct vect3p x1, struct vect3p x2 );
extern struct vect3i outerpro3i( struct vect3i, struct vect3i );
extern struct vect3p outerpro3p( struct vect3p x1, struct vect3p x2 );
extern struct vect3i rshift3i( struct vect3i p, int i );
extern struct vect3i lshift3i( struct vect3i p, int i );
extern struct vect3p rshift3p( struct vect3p p, int i );
extern struct vect3p lshift3p( struct vect3p p, int i );
#define issame3v( p, q ) ( (p).x==(q).x && (p).y==(q).y && (p).z==(q).z )
#define ispara3( p, q ) ( ( (p).x*(q).y - (p).y*(q).x )==0 && ( (p).x*(q).z - (p).z*(q).x )==0 && ( (p).y*(q).z - (p).z*(q).y )==0 )
#define iszero3( p ) ( (p).x==0 && (p).y==0 && (p).z==0 )
#define det3( p, q, r ) ( (p).x*(q).y*(r).z + (q).x*(r).y*(p).z + (r).x*(p).y*(q).z - (p).x*(r).y*(q).z - (q).x*(p).y*(r).z - (r).x*(q).y*(p).z )
#define innerpro3i( p, q ) ( (p).x*(q).x + (p).y*(q).y + (p).z*(q).z )
#define innerpro3p( p, q ) AdjMulDeci( (p).x*(q).x + (p).y*(q).y + (p).z*(q).z )
#define abs3i( p ) ( (int)sqrt( (p).x*(p).x + (p).y*(p).y + (p).z*(p).z ) )
#define Normalize3i( p ) { if( abs3i(p)>0 ) (p)=inscalar3i( abs3i(p) ,scalar3i( DUNIT, (p) ) );}
/* p の大きさをdunitにする */
#define cos3i( p, q ) ( (innerpro3i( p, q ) << DECIMAL) / abs3i(p) / abs3i(q) )
/* p, q のなす角の cos を固定少数で返す */
#define Init3V( p ) { (p).x=0 ; (p).y=0 ; (p).z=0 ;}
/*
* 行列演算関数
*/
extern struct matrix3i addm3i( struct matrix3i A, struct matrix3i B );
#define addm3p( A, B ) ( addm3i( (A), (B) ) )
extern struct matrix3i subm3i( struct matrix3i A, struct matrix3i B );
#define subm3p( A, B ) ( subm3i( (A), (B) ) )
extern struct matrix3i mulmm3i( struct matrix3i A, struct matrix3i B );
extern struct matrix3p mulmm3p( struct matrix3p A, struct matrix3p B );
extern struct vect3i mulmv3i( struct matrix3i A, struct vect3i p );
extern struct vect3p mulmv3p( struct matrix3p A, struct vect3p p );
extern struct vect3i mulmv3pi( struct matrix3p A, struct vect3i p );
/* 3次元vectorの回転 */
extern struct vect3i RotXi( int a, struct vect3i p );
extern struct vect3p RotXp( int a, struct vect3p p );
extern struct vect3i RotYi( int a, struct vect3i p );
extern struct vect3p RotYp( int a, struct vect3p p );
extern struct vect3i RotZi( int a, struct vect3i p );
extern struct vect3p RotZp( int a, struct vect3p p );
extern struct matrix3p RotX( int a );
extern struct matrix3p RotY( int a );
extern struct matrix3p RotZ( int a );
#define Init3M( A ) { (A).xx=0 ; (A).xy=0 ; (A).xz=0 ; (A).yx=0 ; (A).yy=0 ; (A).yz=0 ; (A).zx=0 ; (A).zy=0 ; (A).zz=0 ; }
/* 平面を表す関数 */
#define surffi( s, p ) ( innerpro3i( (s).norl, (p) ) - (s).c )
#define surffp( s, p ) ( innerpro3p( (s).norl, (p) ) - (s).c )